<template>
	<view class="content">
		<u-tabs :list="list" :is-scroll="false" :current="current" @change="change"></u-tabs>
		<view v-if="current==0">
			<view v-for="(patient,index) in patientlist" >
				<view v-if="patient.consultStatus=='待接诊' || patient.consultStatus=='进行中'">
					<patientcard :patient="patient" :index="index"/>
				</view>
			</view>
		</view>
		<view v-if="current==1">
			<view v-for="(patient,index) in patientlist" >
				<view v-if="patient.consultStatus=='已完成'">
					<patientcard :patient="patient" :index="index"/>
				</view>
			</view>
		</view>
		<view>
			<u-tabbar :list="tabbar" active-color="#2979ff" inactive-color="#b9b9b9"></u-tabbar>
		</view>
		<view class="refresh" @click="refreshlist">
			<u-icon name="reload" color=#ffffff size="50" class="thisicon"></u-icon>
		</view>
	</view>
</template>

<script>
	import patientcard from '../../component/patientcard.vue'
	import dispensingcard from '../../component/dispensingcard.vue'
	export default{
		data(){
			return{
				patientlist:[],
				list: [{
					name: '待接诊',
					count:0
					}, {
					name: '已完成'
					}],
				current: 0,
				tabbar:''
			}
		},
		onLoad(){
			this.tabbar=
			[
				{
					iconPath: "home",
					selectedIconPath: "home-fill",
					text: '首页',
					pagePath:"/pages/doctor_mainpage"
				},
				{
					iconPath: "grid",
					selectedIconPath: "grid-fill",
					text: '配药',
					pagePath:"/pages/dispensing/doctor_dispensing"
				},
				// {
				// 	iconPath: "file-text",
				// 	selectedIconPath: "file-text-fill",
				// 	text: '处方',
				// 	pagePath:"/pages/prescription/doctor_prescriptionlist"
				// },
				{
					iconPath: "account",
					selectedIconPath: "account-fill",
					text: '我的',
					pagePath:"/pages/mine/doctor_mypage"
				},
			]
		},
		components:{
			patientcard,
			dispensingcard
		},
		methods:{
			change(index) {
				this.current = index;
				console.log(this.current)
			},
			refreshlist(){
				getApp().globalData.patientlist=[];
				console.log(getApp().globalData.patientlist)
				uni.request({
				    url: getApp().globalData.hostip+'Demo/consult/findByDoc?id='+getApp().globalData.userinfo.nickName, 
				    data: {
				    },
				    success: (res) => {
				        console.log(res.data);
						for(var i=0;i<res.data.length;i++){
							res.data[i].drugIds=res.data[i].drugIds.split(',');
							for(var j=0;j< getApp().globalData.baseDrug.length;j++){
								for(var k=0;k<res.data[i].drugIds.length;k++){
									if(getApp().globalData.baseDrug[j].drugId.toString()==res.data[i].drugIds[k]){
										res.data[i].drugIds.splice(k,1, getApp().globalData.baseDrug[j].drugName)
									}
								}
							}
						}
						res.data.forEach(function(temp){
							getApp().globalData.patientlist.push(
							{
								'consultId':temp.consultId,
								'accountId':temp.accountId,
								'personName':temp.personName,
								'personCardType':'',
								'personCardId':temp.personCardId,
								'personGenderName':temp.personGenderName,
								'personBirthDate':'',
								'personAge':temp.personAge,
								'personPhoneNo':temp.personPhoneNo,
								'question':temp.question,
								'diagnosis':temp.diagnosis,
								'diagnosisIds':'',
								'drugIds':temp.drugIds,
								'photoIds':temp.photoIds.split(','),
								'consultStatus':temp.consultStatus,
								'consultCreateTime':temp.consultCreateTime.replace(".000+00:00","").replace("T"," "),
								'consultAcceptTime':'',
								'consultFinishTime':'',
								'prescriptions':[]
							})
						})
				    }
				});
			this.patientlist=getApp().globalData.patientlist;	
			}
		},
		created(){
			this.patientlist=getApp().globalData.patientlist;
			for(var i=0;i<this.patientlist.length;i++){
				if(this.patientlist[i].consultStatus=='待接诊')
					this.list[0].count++;
			}
		}
	}
</script>

<style scopped>
	page{
		background-color: #f5f5f5;
	}
	.refresh{
		position:fixed;
		/* position: absolute; */
		width: 100rpx;
		height: 100rpx;
		background-color: #007AFF;
		border-radius:50rpx ;
		top:80%;
		left:600rpx;
		text-align: center;
		z-index:999
	}
	.thisicon{
		margin-top: 25rpx;
	}
</style>
